var vm = new Vue({
	el:"#container",
			data:{
				wallets:[],
				totalCount:'',
				pageOrder:1,
				pageCount:'',
				pageSize:'',
				mobile:'',
				name:'',
				picture:'',
				yearName:'2017上半年',
				balance:'',
				carryBalance:'',
				cardNo:'',
				bankName:'',
				phoneNum:'',
				bankIdStr:'',
				idCard:'',
				verificationCode:'',
				minename:'',
				bank:'',
				cardIdstr:'',
				withBank:'',
				withAmount:'',
				withName:'',
				newTradePassword:'',
				confirmTradePassword:'',
				tradePassword:'',
				amount:'',
				subBank:'',
				subAmount:'',
				subPoundage:'',
				password:'',
				oldMobile:'',
				newMobile:'',
				newMobileNext:'',
				oldPassword:'',
				Newpassword:'',
				passwordCon:'',
				certificationStatus:'',
				data:'',
				realNameVerified:'',
				monthIncome:'',
				withdrawalBalance:'',
				myWholeBalance:'',
				settlingBalance:'',
				withdrawalBalance:'',
			},
			mounted:function(){
				this.$nextTick(function(){

					//输入交易密码提现
					$('.passwordDiv input').on('input', function(e) {
			            var number = 6;
			            var pw = $("input[name = 'password']").val();
			            if(pw.length==6){
			            	post('/account/withdrawal',{amount:vm.amount,tradePassword:vm.tradePassword},function(res){
								window.location.href='submit.html?bank='+res.data.bank+'&amount='+res.data.amount+'&poundage='+res.data.poundage;
							});
			            }
			            var list = $('.passwordDiv ul li');
			            for(var i = 0; i < number; i++) {
			                if(pw[i]) {
			                    $(list[i]).text('•');
			                } else {
			                    $(list[i]).text('');
			                };
			            };
			        });
					var pathname=location.pathname;
					var bankname=window.localStorage.getItem('bankName');
					if(bankname){
						vm.bankName=window.localStorage.getItem('bankName')
					}else{
						vm.bankName='';
					}
					// 钱包页面
					if(pathname=='/pages/mine/wallet.html'){
						//信息
						this.mineInfor();
						this.noRead();
						this.balanceMoney();
						// 提现列表
						this.withdrawFunction();
						//上拉加载调用
						refresh(this.refreshData());
					}
					// 密码、登录页面
					if(pathname=='/pages/mine/password.html' || pathname=='/pages/mine/editLoginMobile.html'){
						//信息
						this.mineInfor();
					}
					// 银行卡列表
					if(pathname=='/pages/mine/card.html'){
						this.cardList();
					}
					// 没有银行卡
					if(pathname=='/pages/mine/noCard.html'){
						$('.idCard').blur(function(event) {
							if(isCardID(vm.idCard) !='true'){
								toast(isCardID(vm.idCard))
							}
						});
					}
					// 申请提现页面
					if(pathname=='/pages/mine/withdrawal.html'){
						this.withdrawal();
					}
					//提交页面
					if(pathname=='/pages/mine/submit.html'){
						vm.subBank=decodeURI(this.getParameter('bank'));
						vm.subAmount=this.getParameter('amount');
						vm.subPoundage=this.getParameter('poundage');
					}
					// 修改密码手机号页面
					if(pathname=='/pages/mine/editMobilenext.html'){
						vm.newMobileNext=this.getParameter('newMobile').replace(/^(\d{3})\d{4}(\d+)/,"$1****$2");
					}
					// 修改密码手机号页面
					if(pathname=='/pages/mine/editLogin.html' || pathname=='/pages/mine/editLoginMobile.html' || pathname=='/pages/mine/editMobile.html'){	
						//验证登录密码
						$('#password').blur(function(event) {
							if(fomatPass(vm.password)){
							}else{
								toast('密码必须由6-18位字母与数字组成')
							}
						});
						$('#password1').blur(function(event) {
							if(fomatPass(vm.Newpassword)){
							}else{
								toast('密码必须由6-18位字母与数字组成')
							}
						});
						$('#password2').blur(function(event) {
							if(fomatPass(vm.passwordCon)){
							}else{
								toast('密码必须由6-18位字母与数字组成')
							}
						});
					}
				});
			},
			methods:{
				// 未读消息数
				noRead:function(){
					noParamsGet('/advisor/msg/unread-count',function(res){
						vm.data=res.data;
						if(res.data>9){
							vm.data='9+';
							$('.mine-circle').show();
						}else if(res.data==0){
							$('.mine-circle').hide();
						}else{
							$('.mine-circle').show();
						}
					})
				},
				
				// 头部信息
				mineInfor:function () {
					noParamsGet('/user/info',function(res){
						vm.mobile=res.data.mobile ? res.data.mobile.replace(/^(\d{3})\d{4}(\d+)/,"$1****$2") : '';
						vm.name=res.data.name;
						vm.monthIncome = res.data.monthIncome ? res.data.monthIncome : '0.00';
						vm.withdrawalBalance  = res.data.withdrawalBalance ? res.data.withdrawalBalance : '0.00';
						vm.picture=res.data.picture ? res.data.picture : '../../build/images/touxiang.png';
						vm.realNameVerified=res.data.realNameVerified;
						if(vm.realNameVerified==false){
							$('.cel-yellow').addClass('gray-color');
							$('.cel-yellow').click(function(event) {
								window.location.href='noCard.html'
							});
						}
						vm.phoneNum=res.data.mobile;
					});
				},

				//余额
				balanceMoney:function(){
					noParamsGet('/account/wallet/info',function(res){
						vm.myWholeBalance =res.data.myWholeBalance ? res.data.myWholeBalance :'0.00';
						vm.settlingBalance =res.data.settlingBalance ?res.data.settlingBalance :'0.00';
						vm.withdrawalBalance  =res.data.withdrawalBalance ? res.data.withdrawalBalance :'0.00'  ;
						vm.setTradePassword=res.data.setTradePassword;
						vm.bindingBankCard=res.data.bindingBankCard;
						if(vm.setTradePassword==true){
							$('.wallet-cash-text').hide();
						}else{
							$('.wallet-cash-text').show();
							$('.wallet-cash-btn').removeAttr('href');
						}
						if(vm.bindingBankCard==false){
							$('.in-card').hide();
							$('.no-card').show();
							$('.wallet-cash-btn').removeAttr('href');
						}else{
							$('.in-card').show();
							$('.no-card').hide();
						}
						if(vm.myWholeBalance > 0 && vm.setTradePassword==true && vm.bindingBankCard==true && vm.withdrawalBalance > 0){
							$('.wallet-cash-btn').addClass('cash-btn');
						}else{
							$('.wallet-cash-btn').removeAttr('href');
						}
					});
				},
				
				// 提现记录列表
				withdrawFunction:function(){
					//初始化加载提示
					loader.init();
					get('/account/withdrawal/history',{currentPage:vm.pageOrder},function(res){
						vm.wallets=vm.wallets.concat(res.data.resultList);
						vm.totalCount=res.data.totalCount;
						vm.pageSize=res.data.pageSize;
						vm.pageCount=Math.ceil(vm.totalCount / vm.pageSize);
						//滚动到底部文字判断
						if(res.data.resultList.length < 7){
							refreshText('到底了哦！')
						}else{
							refreshText('上拉加载更多数据')
						}
						if(vm.totalCount == 0){
							$('.wallet-no-text').show();
							refreshText('');
							$('.refresh-tips').hide();
						}else{
							$('.wallet-no-text').hide();
						}
						loader.remove();
					});
				},


				//银行卡列表
				cardList:function(){
					noParamsGet('/advisor/financial-advisor/bank-card/list',function(res){
						vm.cardNo=res.data.cardNo;
						vm.bank=res.data.bank;
						vm.cardIdstr=res.data.idStr;
					});
				},
				//发送验证码
				//钱包验证码
				sendWallet:function(data){
					if($('.password-send').css('color')!='rgb(255, 255, 255)' && $('.tel-code').css('color')!='rgb(102, 102, 102)'){
						post('/user/auth/send/code',{},function(res){
							$('.tel-code').css({'background':'#eee',color:'#666'});
							toast('验证码已发送，请注意查收')
							$('.password-send').css({'background':'#999',color:'#fff','border':'1px solid #999'});
							$(".tel-code").attr({'disabled':'disabled'})
							var validCode=true;
							if (validCode) {
								validCode=false;
								var time=60;
								var t=setInterval(function() {
									time--;
									$(".tel-code").html(time+"S后再次发送");
									if (time==0) {
										clearInterval(t);
									$(".tel-code").removeAttr('disabled').html("重新获取");
									$('.password-send').removeAttr('disabled').html("重新获取");
									$('.tel-code').css({'background':'rgba(0,93,158,0.2)','color':'#005d9e'});
									$('.password-send').css({'background':'rgba(0,93,158,0.2)','color':'#005d9e','border':'1px solid #005d9e'});
										validCode=true;
									}
								},1000)
							}
						})
					}
				},
				//vm.phoneNum
				send:function(data){
					if($('.password-send').css('color')!='rgb(255, 255, 255)' && $('.tel-code').css('color')!='rgb(102, 102, 102)'){
						post('/user/send/mobile-code',{mobile:vm.phoneNum,check:false,registerCheck:data},function(res){
							$('.tel-code').css({'background':'#eee',color:'#666'});
							toast('验证码已发送，请注意查收')
							$('.password-send').css({'background':'#999',color:'#fff','border':'1px solid #999'});
							$(".tel-code").attr({'disabled':'disabled'})
							var validCode=true;
							if (validCode) {
								validCode=false;
								var time=60;
								var t=setInterval(function() {
									time--;
									$(".tel-code").html(time+"S后再次发送");
									if (time==0) {
										clearInterval(t);
									$(".tel-code").removeAttr('disabled').html("重新获取");
									$('.password-send').removeAttr('disabled').html("重新获取");
									$('.tel-code').css({'background':'rgba(0,93,158,0.2)','color':'#005d9e'});
									$('.password-send').css({'background':'rgba(0,93,158,0.2)','color':'#005d9e','border':'1px solid #005d9e'});
										validCode=true;
									}
								},1000)
							}
						})
					}
				},
				//提交银行卡信息
				editInfor:function(){
					post('/advisor/financial-advisor/bank-card/binding',{bankIdStr:window.localStorage.getItem('bankIdstr'),cardNo:delHtmlTag(vm.cardNo),name:vm.minename,idCard:vm.idCard,mobile:vm.phoneNum,verificationCode:vm.verificationCode},function(res){
						toast('保存成功');
						setTimeout("window.location.href='wallet.html'",1000);
					})
				},
				// 设置交易密码
				save:function(){
					post('/user/trade-password/reset',{verificationCode:vm.verificationCode,newTradePassword:vm.newTradePassword,confirmTradePassword:vm.confirmTradePassword},function(res){
						toast('保存成功');
						setTimeout("window.location.href='wallet.html'",1000);
					});
				},
				//解除绑定
				remove:function(){
					get('/advisor/financial-advisor/bank-card/cancel-binding',{idStr:vm.cardIdstr},function(res){
						window.location.href='wallet.html';
						window.localStorage.removeItem('bankName');
					});
				},
				// 申请提现
				withdrawal:function(){
					noParamsGet('/account/withdrawal/info',function(res){
						vm.withBank=res.data.bank;
						vm.withAmount=res.data.amount;
						vm.withName=res.data.name;
					});
				},
				refreshData:function(){
					return function(){
						if(vm.pageCount>vm.pageOrder){
							vm.pageOrder++;
							console.log(vm.pageOrder)
							vm.withdrawFunction();
						}else{
							refreshText('到底了哦！')
						}
					}
				},
				// 更换手机号
				changeMobile:function(){
					post('/user/change/mobile',{newMobileNo:vm.phoneNum,verificationCode:vm.verificationCode,password:vm.password},function(res){
						toast('保存成功');
						setTimeout("window.location.href='settings.html'",1000);
					});
				},
				// 修改登录密码
				editLogin:function(){
					post('/user/reset/password',{oldPassword:vm.oldPassword,password:vm.Newpassword},function(res){
						toast('保存成功');
      					window.localStorage.removeItem(siteTokenKey);
      					window.localStorage.removeItem('password');
						setTimeout("window.location.href='/pages/login/login.html'",1000);
					});
				},
				editLoginMobile:function(){
					post('/user/reset/login-password',{verificationCode:vm.verificationCode,newPassword:vm.Newpassword,confirmPassword:vm.passwordCon},function(res){
						toast('保存成功');
      					window.localStorage.removeItem(siteTokenKey);
      					window.localStorage.removeItem('password');
						setTimeout("window.location.href='/pages/login/login.html'",1000);
					});
				},
				getParameter:function(name){
					var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
					var r = window.location.search.substr(1).match(reg);
					if (r!=null) return (r[2]); return null;
				},
			},
		})
